package com.cn.jwt.zy.jwt.config;

import com.cn.jwt.zy.jwt.filter.JwtAuthentication;
import com.cn.jwt.zy.jwt.filter.JwtLoginFilter;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * 安全配置类
 *
 * @author zhangyi
 * @date 2018/12/14 14:05
 */
@Configuration
@Order(SecurityProperties.BASIC_AUTH_ORDER)
public class JwtConfig extends WebSecurityConfigurerAdapter{

    @Override
    public void configure(WebSecurity web) throws Exception {
        super.configure(web);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.cors().and().csrf().disable().authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .addFilter(new JwtLoginFilter(authenticationManager()))
                .addFilter(new JwtAuthentication(authenticationManager()));
        super.configure(http);
    }
}
